//
//  ShiTiQKCJCell.m
//  MyProject
//
//  Created by Pei on 16/7/31.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

#import "ShiTiQKCJCell.h"

@implementation ShiTiQKCJCell

{
    UILabel *_headerLbl;
    UILabel *_dateLbl;
    
    UILabel *_titleLbl;
    UILabel *_detailLbl;
    
    UILabel *_statusLbl;
    
    UIImageView *_arrowImageView;
    
    UIView *_centerLineView;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        
        _mSelected = NO;
        CGRect indicatorFrame = CGRectMake(-20, fabs(self.frame.size.height - 20)/ 2, 20, 20);
        _mSelectedIndicator = [[UIImageView alloc] initWithFrame:indicatorFrame];
        _mSelectedIndicator.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
        [self.contentView addSubview:_mSelectedIndicator];
        
        
        self.backgroundColor = kWhiteColor;
        
        _headerLbl = [[UILabel alloc] init];
        _headerLbl.frame = CGRectMake(10.0f, (60.0f-55.0f)/2.0f, 0.0f, 55.0f);
        _headerLbl.layer.masksToBounds = YES;
        _headerLbl.layer.cornerRadius = 55.0f/2.0f;
        _headerLbl.backgroundColor = [UIColor clearColor];
        _headerLbl.text = @"用电";
        _headerLbl.textColor = kWhiteColor;
        _headerLbl.textAlignment = NSTextAlignmentCenter;
        _headerLbl.font = kAppFont(Home_Big_Size+4.0f);
        [self addSubview:_headerLbl];
        
        _dateLbl = [[UILabel alloc] init];
        _dateLbl.frame = CGRectMake(kDeviceWidth-10.0f-70.0f, _headerLbl.origin.y+10.0f, 70.0f, Home_Small_Size);
        _dateLbl.text = @"2016-06-23";
        _dateLbl.textAlignment = NSTextAlignmentRight;
        _dateLbl.font = kAppFont(Home_Small_Size);
        _dateLbl.textColor = kRGB(205, 206, 207);
        [self addSubview:_dateLbl];
        
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.frame = CGRectMake(_headerLbl.right+10.0f, _headerLbl.origin.y+10.0f, kDeviceWidth-10.0f*2-_dateLbl.width, Home_Small_Size+2.0f);
        _titleLbl.text = @"检查任务-专项检查0001";
        _titleLbl.font = kAppFont(Home_Small_Size+2.0f);
        _titleLbl.textColor = kBlackColor;//kRGB(167, 168, 168);
        [self addSubview:_titleLbl];
        
        _detailLbl = [[UILabel alloc] init];
        _detailLbl.frame = CGRectMake(_titleLbl.origin.x, _titleLbl.bottom+20.0f, kDeviceWidth-10.0f-10.0f*2.0f-_headerLbl.width, Home_Small_Size);
        _detailLbl.text = @"公司-工区   机械";
        _detailLbl.font = kAppFont(Home_Small_Size);
        _detailLbl.textColor = kBlackColor;//kRGB(167, 168, 168);
        [self addSubview:_detailLbl];
        
        _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"06jiantou-"]];
        _arrowImageView.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f,_detailLbl.origin.y+(Home_Small_Size-(19.0f/2.0f))/2.0f, 10.0f/2.0f, 19.0f/2.0f);
        [self addSubview:_arrowImageView];
        
        _centerLineView = [[UIView alloc] initWithFrame:CGRectMake(_titleLbl.origin.x, _detailLbl.bottom+5.0f, kDeviceWidth-10.0f-10.0f*2.0f-_headerLbl.width, 0.5f)];
        _centerLineView.backgroundColor = kGreenColor;
        //[self addSubview:_centerLineView];
        
//        _statusLbl = [[UILabel alloc] init];
//        _statusLbl.frame = CGRectMake(_titleLbl.origin.x, _centerLineView.bottom+8.0f, 200.0f, Home_Small_Size);
//        _statusLbl.text = @"专项检查";
//        _statusLbl.font = kAppFont(Home_Small_Size);
//        _statusLbl.textColor = kRGB(95, 199, 247);
//        [self addSubview:_statusLbl];
        
        
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 60.0f-0.5f, kDeviceWidth-10*2, 0.5f)];
        lineView.backgroundColor = kGreenColor;
        [self addSubview:lineView];
    }
    
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:YES];
    
    if (_mSelected)
    {
        if (((UITableView *)self.superview).isEditing)
        {
            self.backgroundView.backgroundColor = [UIColor colorWithRed:223.0/255.0 green:230.0/255.0 blue:250.0/255.0 alpha:1.0];
        }
        else
        {
            self.backgroundView.backgroundColor = [UIColor clearColor];
        }
        
        self.textLabel.textColor = [UIColor darkTextColor];
        [_mSelectedIndicator setImage:[UIImage imageNamed:@"checked_on"]];
        //self.accessoryType = UITableViewCellAccessoryCheckmark;
        
    }
    else
    {
        self.backgroundView.backgroundColor = [UIColor clearColor];
        self.textLabel.textColor = [UIColor grayColor];
        [_mSelectedIndicator setImage:[UIImage imageNamed:@"checked_off"]];
        self.accessoryType = UITableViewCellAccessoryNone;
        
    }
    
    
    
    [UIView commitAnimations];
    
    if (((UITableView *)self.superview.superview).isEditing)
    {
        _headerLbl.frame = CGRectMake(20+10+10.0f, (60.0f-55.0f)/2.0f, 0.0f, 55.0f);
        //_dateLbl.frame = CGRectMake(kDeviceWidth-10.0f-70.0f, _headerLbl.origin.y, 70.0f, Home_Small_Size);
        _titleLbl.frame = CGRectMake(_headerLbl.right+10.0f, _headerLbl.origin.y+10.0f, kDeviceWidth-10.0f, Home_Small_Size+2.0f);
        _detailLbl.frame = CGRectMake(_titleLbl.origin.x, _titleLbl.bottom+10.0f, kDeviceWidth-10.0f-10.0f*2.0f-_headerLbl.width, Home_Small_Size);
        _arrowImageView.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f,_detailLbl.origin.y+(Home_Small_Size-(19.0f/2.0f))/2.0f, 10.0f/2.0f, 19.0f/2.0f);
        _centerLineView.frame = CGRectMake(_titleLbl.origin.x, _detailLbl.bottom+5.0f, kDeviceWidth-10.0f-10.0f*2.0f-_headerLbl.width, 0.5f);
        _statusLbl.frame = CGRectMake(_titleLbl.origin.x, _centerLineView.bottom+8.0f, 200.0f, Home_Small_Size);
    }
    else
    {
        _headerLbl.frame = CGRectMake(10.0f, (60.0f-55.0f)/2.0f, 0.0f, 55.0f);
        //_dateLbl.frame = CGRectMake(kDeviceWidth-10.0f-70.0f, _headerLbl.origin.y, 70.0f, Home_Small_Size);
        _titleLbl.frame = CGRectMake(_headerLbl.right+10.0f, _headerLbl.origin.y+10.0f, kDeviceWidth-10.0f, Home_Small_Size+2.0f);
        _detailLbl.frame = CGRectMake(_titleLbl.origin.x, _titleLbl.bottom+10.0f, kDeviceWidth-10.0f-10.0f*2.0f-_headerLbl.width, Home_Small_Size);
        _arrowImageView.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f,_detailLbl.origin.y+(Home_Small_Size-(19.0f/2.0f))/2.0f, 10.0f/2.0f, 19.0f/2.0f);
        _centerLineView.frame = CGRectMake(_titleLbl.origin.x, _detailLbl.bottom+5.0f, kDeviceWidth-10.0f-10.0f*2.0f-_headerLbl.width, 0.5f);
        _statusLbl.frame = CGRectMake(_titleLbl.origin.x, _centerLineView.bottom+8.0f, 200.0f, Home_Small_Size);
    }
    
}


- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    [self setNeedsLayout];
}


#pragma mark -
#pragma mark Public

- (void)changeMSelectedState
{
    _mSelected = !_mSelected;
    [self setNeedsLayout];
}


- (void)showWithData:(NSDictionary*)data
{
    _titleLbl.text = [data valueForKey:@"InfoName"];
    _detailLbl.text = [NSString stringWithFormat:@"%@-%@", [data valueForKey:@"ProjectName"], [data valueForKey:@"DeptName"]];
    
//    NSArray *tempArray = [[NSUserDefaults standardUserDefaults] objectForKey:Dic_ProjectState];
//    if (tempArray != nil && tempArray.count > 0) {
//        for (NSDictionary *fff in tempArray) {
//            if ([[fff valueForKey:@"Value"] intValue] == [[data valueForKey:@"Status"] intValue]) {
//                _statusLbl.text = [fff valueForKey:@"Name"];
//            }
//        }
//    }
}

@end
